package self.seon.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Seon
 * @date 2022/9/9 2:35
 */
@Slf4j
@Configuration
public class CrossConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 设置允许跨域的路径
        registry.addMapping("/**")
                // 允许跨域请求的域名
                .allowedOriginPatterns("*")
                // 允许cookie
                .allowCredentials(true)
                // 允许的方法种类
                .allowedMethods("GET", "POST", "DELETE", "PUT")
                // 允许的header的属性
                .allowedHeaders("*")
                // 跨域运行时间
                .maxAge(3600);
    }
}
